package com.stone.framework.gateway.util;

import java.nio.charset.Charset;

import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;

import com.stone.framework.core.util.Beans;
import com.stone.framework.message.ResMessage;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class ResponseUtil {

    public static Mono<Void> mono(ServerHttpResponse response, HttpStatus status, String body) {
        response.setStatusCode(status);
        String resMessage = Beans.beanToString(ResMessage.fail(body));
        DataBuffer data = response.bufferFactory().wrap(resMessage.getBytes(Charset.forName("UTF-8")));
        return response.writeWith(Flux.just(data));
    }

}
